package org.jeie.actions;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

import org.jeie.main.Action;
import org.jeie.messages.Messages;

public class RotateAction implements Action {
	public int degrees;
	public RotateAction(int degrees) {
		this.degrees = degrees;
	}
	public BufferedImage apply(BufferedImage img) {
		return rotate(img, degrees);
	}
	public String getName() {
		return Messages.getString("Action.Rotate"); //$NON-NLS-1$
	}
	public static BufferedImage rotate(BufferedImage img, int degrees) {
		int w = img.getWidth();
		int h = img.getHeight();
		BufferedImage newIMG = new BufferedImage(w, h, img.getColorModel()
				.getTransparency());
		Graphics2D g = newIMG.createGraphics();
		g.rotate(Math.toRadians(degrees), w / 2, h / 2);
		g.drawImage(img, 0, 0, null);
		g.dispose();
		return newIMG;
	}
}
